package com.boomkeeper.core.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.boomkeeper.core.model.ChangeOrder;
import com.boomkeeper.core.model.ChangeOrderData;

public class MailUtils {
	
	public static Map<String, Object> transferDataToMap(ChangeOrderData changeOrderData){
		List<ChangeOrder> changeOrderList = changeOrderData.getChangeOrderList();
		List<String> publishInstructionList = changeOrderData.getPublishInstructionList();
		
		Map<String, Object> mailData = new HashMap<>();
		List<Map<String, Object>> subChangeOrderList = new ArrayList<>(changeOrderList.size());
		
		for (ChangeOrder changeOrder : changeOrderList) {
			Map<String, Object> changeOrderMap = new HashMap<>();
			changeOrderMap.put("type", changeOrder.isBug() ? "Bug" : "需求");
			changeOrderMap.put("redmine", changeOrder.getRedmine());
			changeOrderMap.put("subject", changeOrder.getSubject());
			changeOrderMap.put("desc", changeOrder.getDesc());
			changeOrderMap.put("author", changeOrder.getAuthor());
			changeOrderMap.put("reviewer", changeOrder.getReviewer());
			changeOrderMap.put("date", changeOrder.getDate());
			changeOrderMap.put("propertiesFile", changeOrder.getPropertiesFile());
			changeOrderMap.put("mdaFile", changeOrder.getMdaFile());
			changeOrderMap.put("sqlFile", changeOrder.getSqlFile());
			changeOrderMap.put("changeOrderFileName", changeOrder.getChangeOrderFileName());
			subChangeOrderList.add(changeOrderMap);
		}
		
		mailData.put("changeOrderList", subChangeOrderList);
		mailData.put("publishInstructionList", publishInstructionList);
		
		return mailData;
	}
}